package View;

import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import Bussiness.Update_Action;
import Model.KhoaHoc;

/**
 * 
 * @author Nhóm java lớp PNV2T - Nguyễn Thị Lệ Đài - Nguyễn Chí Hướng
 * 
 */
public class SuaKhoaHoc extends javax.swing.JFrame {
	KhoaHoc newKH = null;

	/** Creates new form SuaKhoaHoc */
	public SuaKhoaHoc(int ID, String TenKhoa, String NgayBatDau) {
		setAlwaysOnTop(true);
		setResizable(false);
		setIconImage(Toolkit.getDefaultToolkit().getImage(
				SuaKhoaHoc.class.getResource("/Icon/QLSV.jpg")));
		try {
			UIManager
					.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch (UnsupportedLookAndFeelException ex) {
			ex.printStackTrace();
		} catch (IllegalAccessException ex) {
			ex.printStackTrace();
		} catch (InstantiationException ex) {
			ex.printStackTrace();
		} catch (ClassNotFoundException ex) {
			ex.printStackTrace();
		}
		initComponents();
		setLocation(520, 50);
		newKH = new KhoaHoc(TenKhoa, NgayBatDau);
		newKH.setID(ID);

		txt_NgayBatDau.setText(newKH.getBatDau());
		txt_TenKhoa.setText(newKH.getTenKhoa());
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed"
	// desc=" Generated Code ">//GEN-BEGIN:initComponents
	private void initComponents() {
		jPanel1 = new javax.swing.JPanel();
		jToolBar1 = new javax.swing.JToolBar();
		btn_CapNhap = new javax.swing.JButton();
		jSeparator1 = new javax.swing.JSeparator();
		jLabel3 = new javax.swing.JLabel();
		txt_TenKhoa = new javax.swing.JTextField();
		jLabel4 = new javax.swing.JLabel();
		txt_NgayBatDau = new javax.swing.JTextField();
		jLabel5 = new javax.swing.JLabel();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("S\u1eeda th\u00f4ng tin kh\u00f3a h\u1ecdc ...");
		jPanel1.setBackground(SystemColor.activeCaption);
		jToolBar1.setBackground(SystemColor.inactiveCaption);
		jToolBar1.setFloatable(false);

		btn_CapNhap.setBackground(new java.awt.Color(227, 239, 249));
		btn_CapNhap.setFont(new java.awt.Font("Times New Roman", 1, 13));
		btn_CapNhap.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/Icon/Sua.png")));
		btn_CapNhap.setText("C\u1eadp Nh\u1eadp");
		btn_CapNhap.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btn_CapNhapActionPerformed(evt);
			}
		});

		jToolBar1.add(btn_CapNhap);

		jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel3.setText("T\u00ean kh\u00f3a :");

		txt_TenKhoa.setFont(new java.awt.Font("Times New Roman", 0, 13));
		txt_TenKhoa.setBorder(javax.swing.BorderFactory
				.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

		jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel4.setText("Ng\u00e0y b\u1eaft \u0111\u1ea7u :");

		txt_NgayBatDau.setFont(new java.awt.Font("Times New Roman", 0, 13));
		txt_NgayBatDau.setBorder(javax.swing.BorderFactory
				.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

		jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 13));
		jLabel5.setText("( Th\u00e1ng/Ng\u00e0y/N\u0103m )");

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout
				.setHorizontalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel4)
														.addComponent(jLabel3))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																txt_TenKhoa,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																170,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addGroup(
																jPanel1Layout
																		.createSequentialGroup()
																		.addComponent(
																				txt_NgayBatDau,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				107,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				jLabel5))))
						.addGroup(
								jPanel1Layout
										.createParallelGroup(
												javax.swing.GroupLayout.Alignment.TRAILING,
												false)
										.addComponent(
												jSeparator1,
												javax.swing.GroupLayout.Alignment.LEADING)
										.addComponent(
												jToolBar1,
												javax.swing.GroupLayout.Alignment.LEADING,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												330, Short.MAX_VALUE)));
		jPanel1Layout
				.setVerticalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addComponent(
												jToolBar1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												38,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												jSeparator1,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												2,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGap(22, 22, 22)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel3)
														.addComponent(
																txt_TenKhoa,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																26,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel4)
														.addComponent(
																txt_NgayBatDau,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																26,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel5))
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
				javax.swing.GroupLayout.DEFAULT_SIZE,
				javax.swing.GroupLayout.PREFERRED_SIZE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
				javax.swing.GroupLayout.DEFAULT_SIZE,
				javax.swing.GroupLayout.PREFERRED_SIZE));
		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void btn_CapNhapActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_

		String TenKhoa = txt_TenKhoa.getText();
		String NgayBatDau = txt_NgayBatDau.getText();

		if (TenKhoa.equalsIgnoreCase("")) {
			JOptionPane.showMessageDialog(null, "Chưa nhập tên khóa!",
					"Null Values !", JOptionPane.ERROR_MESSAGE);
			txt_TenKhoa.requestFocus();
		} else if (NgayBatDau.equalsIgnoreCase("")) {
			JOptionPane.showMessageDialog(null, "Chưa nhập ngày bắt đầu!",
					"Null Values !", JOptionPane.ERROR_MESSAGE);
			txt_NgayBatDau.requestFocus();
		} else {
			newKH.setTenKhoa(TenKhoa);
			newKH.setBatDau(NgayBatDau);
			Update_Action ua = new Update_Action();
			if (ua.SuaKhoaHoc(newKH) == true) {
				int j = JOptionPane.showConfirmDialog(null,
						"Sửa thành công! Bạn có muốn tiếp tục sửa không?",
						"Continue ... !", 2);
				if (j != 0)
					this.dispose();
			} else {
				JOptionPane.showMessageDialog(this, "Không sửa được!");
			}
			ua.Close();
		}
	}// GEN-LAST:event_btn_CapNhapActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton btn_CapNhap;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JSeparator jSeparator1;
	private javax.swing.JToolBar jToolBar1;
	private javax.swing.JTextField txt_NgayBatDau;
	private javax.swing.JTextField txt_TenKhoa;
	// End of variables declaration//GEN-END:variables

}
